package com.spring.boot.demo.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @Date: 2022/11/19 22:14
 * @Description ES客户端配置类
 */
@Configuration
public class RestClientConfig {

    @Bean(name = "highRestClient")
    public RestHighLevelClient restHighLevelClient() {
        // 1、创建IP地址对象: 这里就是写ES数据库的IP地址信息，如果有多个ES结点，那就可以写多个IP地址
        // ES数据库，默认是9200端口
        HttpHost httpHost = new HttpHost("localhost", 9200, "http");
        // 2、创建低级客户端对象:
        RestClientBuilder builder = RestClient.builder(httpHost);
        // 3、创建 RestHighLevelClient 对象
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
        return restHighLevelClient;
    }

}
